{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 136,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Exception reporting mode: Plain\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "%xmode plain"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>body {\n",
       "    margin: 0;\n",
       "    font-family: Helvetica;\n",
       "}\n",
       "table.dataframe {\n",
       "    border-collapse: collapse;\n",
       "    border: none;\n",
       "}\n",
       "table.dataframe tr {\n",
       "    border: none;\n",
       "}\n",
       "table.dataframe td, table.dataframe th {\n",
       "    margin: 0;\n",
       "    border: 1px solid white;\n",
       "    padding-left: 0.25em;\n",
       "    padding-right: 0.25em;\n",
       "}\n",
       "table.dataframe th:not(:empty) {\n",
       "    background-color: #fec;\n",
       "    text-align: left;\n",
       "    font-weight: normal;\n",
       "}\n",
       "table.dataframe tr:nth-child(2) th:empty {\n",
       "    border-left: none;\n",
       "    border-right: 1px dashed #888;\n",
       "}\n",
       "table.dataframe td {\n",
       "    border: 2px solid #ccf;\n",
       "    background-color: #f4f4ff;\n",
       "}\n",
       "</style>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 164,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from IPython.core.display import HTML\n",
    "HTML('<style>{}</style>'.format(open('style-table.css').read()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "      <th>director</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>     North by Northwest</td>\n",
       "      <td> 1959</td>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>              Notorious</td>\n",
       "      <td> 1946</td>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td> The Philadelphia Story</td>\n",
       "      <td> 1940</td>\n",
       "      <td>     George Cukor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>       To Catch a Thief</td>\n",
       "      <td> 1955</td>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>        His Girl Friday</td>\n",
       "      <td> 1940</td>\n",
       "      <td>     Howard Hawks</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    title  year          director\n",
       "0      North by Northwest  1959  Alfred Hitchcock\n",
       "1               Notorious  1946  Alfred Hitchcock\n",
       "2  The Philadelphia Story  1940      George Cukor\n",
       "3        To Catch a Thief  1955  Alfred Hitchcock\n",
       "4         His Girl Friday  1940      Howard Hawks"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1 = pd.read_csv('sample.csv')\n",
    "df1.columns = map(str.lower, df1.columns)\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "title       object\n",
       "year         int64\n",
       "director    object\n",
       "dtype: object"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<pandas.core.groupby.DataFrameGroupBy object at 0x7f689c0caac8>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.groupby('director')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "      <th>director</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>     North by Northwest</td>\n",
       "      <td> 1959</td>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>              Notorious</td>\n",
       "      <td> 1946</td>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td> The Philadelphia Story</td>\n",
       "      <td> 1940</td>\n",
       "      <td>     George Cukor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>       To Catch a Thief</td>\n",
       "      <td> 1955</td>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>        His Girl Friday</td>\n",
       "      <td> 1940</td>\n",
       "      <td>     Howard Hawks</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    title  year          director\n",
       "0      North by Northwest  1959  Alfred Hitchcock\n",
       "1               Notorious  1946  Alfred Hitchcock\n",
       "2  The Philadelphia Story  1940      George Cukor\n",
       "3        To Catch a Thief  1955  Alfred Hitchcock\n",
       "4         His Girl Friday  1940      Howard Hawks"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.groupby('director').head()  # looks the same!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.groupby('director').head().equals(df1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "      <th>director</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td> NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td> NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td> NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td> NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>George Cukor</th>\n",
       "      <td> NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td> NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td> NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td> NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Howard Hawks</th>\n",
       "      <td> NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td> NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 title  year director\n",
       "director                             \n",
       "Alfred Hitchcock   NaN   NaN      NaN\n",
       "Alfred Hitchcock   NaN   NaN      NaN\n",
       "George Cukor       NaN   NaN      NaN\n",
       "Alfred Hitchcock   NaN   NaN      NaN\n",
       "Howard Hawks       NaN   NaN      NaN"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.reindex_axis(df1.director)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('Alfred Hitchcock',                 title  year          director\n",
       "  0  North by Northwest  1959  Alfred Hitchcock\n",
       "  1           Notorious  1946  Alfred Hitchcock\n",
       "  3    To Catch a Thief  1955  Alfred Hitchcock),\n",
       " ('George Cukor',                     title  year      director\n",
       "  2  The Philadelphia Story  1940  George Cukor),\n",
       " ('Howard Hawks',              title  year      director\n",
       "  4  His Girl Friday  1940  Howard Hawks)]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(df1.groupby('director'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "      <th>director</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td> North by Northwest</td>\n",
       "      <td> 1959</td>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>          Notorious</td>\n",
       "      <td> 1946</td>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>   To Catch a Thief</td>\n",
       "      <td> 1955</td>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                title  year          director\n",
       "0  North by Northwest  1959  Alfred Hitchcock\n",
       "1           Notorious  1946  Alfred Hitchcock\n",
       "3    To Catch a Thief  1955  Alfred Hitchcock"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.groupby('director').get_group('Alfred Hitchcock')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td>     North by Northwest</td>\n",
       "      <td> 1959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>George Cukor</th>\n",
       "      <td> The Philadelphia Story</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Howard Hawks</th>\n",
       "      <td>        His Girl Friday</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                   title  year\n",
       "director                                      \n",
       "Alfred Hitchcock      North by Northwest  1959\n",
       "George Cukor      The Philadelphia Story  1940\n",
       "Howard Hawks             His Girl Friday  1940"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.groupby('director').first()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td>       To Catch a Thief</td>\n",
       "      <td> 1955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>George Cukor</th>\n",
       "      <td> The Philadelphia Story</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Howard Hawks</th>\n",
       "      <td>        His Girl Friday</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                   title  year\n",
       "director                                      \n",
       "Alfred Hitchcock        To Catch a Thief  1955\n",
       "George Cukor      The Philadelphia Story  1940\n",
       "Howard Hawks             His Girl Friday  1940"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.groupby('director').last()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td>       To Catch a Thief</td>\n",
       "      <td> 1959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>George Cukor</th>\n",
       "      <td> The Philadelphia Story</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Howard Hawks</th>\n",
       "      <td>        His Girl Friday</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                   title  year\n",
       "director                                      \n",
       "Alfred Hitchcock        To Catch a Thief  1959\n",
       "George Cukor      The Philadelphia Story  1940\n",
       "Howard Hawks             His Girl Friday  1940"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.groupby('director').max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "title    To Catch a Thief\n",
       "year                 1959\n",
       "Name: Alfred Hitchcock, dtype: object"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.groupby('director').max().ix['Alfred Hitchcock']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">Alfred Hitchcock</th>\n",
       "      <th>0</th>\n",
       "      <td>     North by Northwest</td>\n",
       "      <td> 1959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>              Notorious</td>\n",
       "      <td> 1946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>       To Catch a Thief</td>\n",
       "      <td> 1955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>George Cukor</th>\n",
       "      <th>2</th>\n",
       "      <td> The Philadelphia Story</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Howard Hawks</th>\n",
       "      <th>4</th>\n",
       "      <td>        His Girl Friday</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     title  year\n",
       "director                                        \n",
       "Alfred Hitchcock 0      North by Northwest  1959\n",
       "                 1               Notorious  1946\n",
       "                 3        To Catch a Thief  1955\n",
       "George Cukor     2  The Philadelphia Story  1940\n",
       "Howard Hawks     4         His Girl Friday  1940"
      ]
     },
     "execution_count": 161,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2 = df1.groupby(['director', df1.index]).first()\n",
    "df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>director</th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "      <td>     North by Northwest</td>\n",
       "      <td> 1959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "      <td>              Notorious</td>\n",
       "      <td> 1946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "      <td>       To Catch a Thief</td>\n",
       "      <td> 1955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>     George Cukor</td>\n",
       "      <td> The Philadelphia Story</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>     Howard Hawks</td>\n",
       "      <td>        His Girl Friday</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           director                   title  year\n",
       "0  Alfred Hitchcock      North by Northwest  1959\n",
       "1  Alfred Hitchcock               Notorious  1946\n",
       "3  Alfred Hitchcock        To Catch a Thief  1955\n",
       "2      George Cukor  The Philadelphia Story  1940\n",
       "4      Howard Hawks         His Girl Friday  1940"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df3 = df2.reset_index('director')\n",
    "df3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "      <th>director</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>     North by Northwest</td>\n",
       "      <td> 1959</td>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>              Notorious</td>\n",
       "      <td> 1946</td>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>       To Catch a Thief</td>\n",
       "      <td> 1955</td>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td> The Philadelphia Story</td>\n",
       "      <td> 1940</td>\n",
       "      <td>     George Cukor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>        His Girl Friday</td>\n",
       "      <td> 1940</td>\n",
       "      <td>     Howard Hawks</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    title  year          director\n",
       "0      North by Northwest  1959  Alfred Hitchcock\n",
       "1               Notorious  1946  Alfred Hitchcock\n",
       "3        To Catch a Thief  1955  Alfred Hitchcock\n",
       "2  The Philadelphia Story  1940      George Cukor\n",
       "4         His Girl Friday  1940      Howard Hawks"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df4 = df3[['title', 'year', 'director']] #.equals(df1)\n",
    "df4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "      <th>director</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>     North by Northwest</td>\n",
       "      <td> 1959</td>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>              Notorious</td>\n",
       "      <td> 1946</td>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td> The Philadelphia Story</td>\n",
       "      <td> 1940</td>\n",
       "      <td>     George Cukor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>       To Catch a Thief</td>\n",
       "      <td> 1955</td>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>        His Girl Friday</td>\n",
       "      <td> 1940</td>\n",
       "      <td>     Howard Hawks</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    title  year          director\n",
       "0      North by Northwest  1959  Alfred Hitchcock\n",
       "1               Notorious  1946  Alfred Hitchcock\n",
       "2  The Philadelphia Story  1940      George Cukor\n",
       "3        To Catch a Thief  1955  Alfred Hitchcock\n",
       "4         His Girl Friday  1940      Howard Hawks"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df4.sort_index()#.equals(df1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "      <th>director</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>     North by Northwest</td>\n",
       "      <td> 1959</td>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>              Notorious</td>\n",
       "      <td> 1946</td>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td> The Philadelphia Story</td>\n",
       "      <td> 1940</td>\n",
       "      <td>     George Cukor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>       To Catch a Thief</td>\n",
       "      <td> 1955</td>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>        His Girl Friday</td>\n",
       "      <td> 1940</td>\n",
       "      <td>     Howard Hawks</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    title  year          director\n",
       "0      North by Northwest  1959  Alfred Hitchcock\n",
       "1               Notorious  1946  Alfred Hitchcock\n",
       "2  The Philadelphia Story  1940      George Cukor\n",
       "3        To Catch a Thief  1955  Alfred Hitchcock\n",
       "4         His Girl Friday  1940      Howard Hawks"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "title       object\n",
       "year         int64\n",
       "director    object\n",
       "dtype: object"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "title       object\n",
       "year         int64\n",
       "director    object\n",
       "dtype: object"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df4.sort_index().dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ True,  True,  True,  True,  True], dtype=bool)"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.index == df4.sort_index().index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                    title  year          director\n",
      "0      North by Northwest  1959  Alfred Hitchcock\n",
      "1               Notorious  1946  Alfred Hitchcock\n",
      "2  The Philadelphia Story  1940      George Cukor\n",
      "3        To Catch a Thief  1955  Alfred Hitchcock\n",
      "4         His Girl Friday  1940      Howard Hawks\n",
      "  title  year director\n",
      "0  True  True     True\n",
      "1  True  True     True\n",
      "2  True  True     True\n",
      "3  True  True     True\n",
      "4  True  True     True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "print(df1)\n",
    "print(df1 == df4.sort_index())\n",
    "print(df1.equals(df4.sort_index()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>level_1</th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td> 0</td>\n",
       "      <td>     North by Northwest</td>\n",
       "      <td> 1959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td> 1</td>\n",
       "      <td>              Notorious</td>\n",
       "      <td> 1946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td> 3</td>\n",
       "      <td>       To Catch a Thief</td>\n",
       "      <td> 1955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>George Cukor</th>\n",
       "      <td> 2</td>\n",
       "      <td> The Philadelphia Story</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Howard Hawks</th>\n",
       "      <td> 4</td>\n",
       "      <td>        His Girl Friday</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  level_1                   title  year\n",
       "director                                               \n",
       "Alfred Hitchcock        0      North by Northwest  1959\n",
       "Alfred Hitchcock        1               Notorious  1946\n",
       "Alfred Hitchcock        3        To Catch a Thief  1955\n",
       "George Cukor            2  The Philadelphia Story  1940\n",
       "Howard Hawks            4         His Girl Friday  1940"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.reset_index(1)\n",
    "#'director')\n",
    "#pd.DataFrame(index=df2.index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "level_1                         2\n",
      "title      The Philadelphia Story\n",
      "year                         1940\n",
      "Name: George Cukor, dtype: object\n",
      "                  level_1               title  year\n",
      "director                                           \n",
      "Alfred Hitchcock        0  North by Northwest  1959\n",
      "Alfred Hitchcock        1           Notorious  1946\n",
      "Alfred Hitchcock        3    To Catch a Thief  1955\n",
      "Index(['Alfred Hitchcock', 'Alfred Hitchcock', 'Alfred Hitchcock', 'George Cukor', 'Howard Hawks'], dtype='object')\n"
     ]
    }
   ],
   "source": [
    "x = df2.reset_index(1)\n",
    "print(x.ix['George Cukor'])\n",
    "print(x.ix['Alfred Hitchcock'])\n",
    "print(x.index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td>     North by Northwest</td>\n",
       "      <td> 1959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td>              Notorious</td>\n",
       "      <td> 1946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>George Cukor</th>\n",
       "      <td> The Philadelphia Story</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td>       To Catch a Thief</td>\n",
       "      <td> 1955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Howard Hawks</th>\n",
       "      <td>        His Girl Friday</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                   title  year\n",
       "director                                      \n",
       "Alfred Hitchcock      North by Northwest  1959\n",
       "Alfred Hitchcock               Notorious  1946\n",
       "George Cukor      The Philadelphia Story  1940\n",
       "Alfred Hitchcock        To Catch a Thief  1955\n",
       "Howard Hawks             His Girl Friday  1940"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y = df1.set_index('director')\n",
    "y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "title    The Philadelphia Story\n",
       "year                       1940\n",
       "Name: George Cukor, dtype: object"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y.ix['George Cukor']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td> North by Northwest</td>\n",
       "      <td> 1959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td>          Notorious</td>\n",
       "      <td> 1946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td>   To Catch a Thief</td>\n",
       "      <td> 1955</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               title  year\n",
       "director                                  \n",
       "Alfred Hitchcock  North by Northwest  1959\n",
       "Alfred Hitchcock           Notorious  1946\n",
       "Alfred Hitchcock    To Catch a Thief  1955"
      ]
     },
     "execution_count": 108,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y.ix['Alfred Hitchcock']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "title    The Philadelphia Story\n",
       "year                       1940\n",
       "Name: George Cukor, dtype: object"
      ]
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y.loc['George Cukor']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td> North by Northwest</td>\n",
       "      <td> 1959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td>          Notorious</td>\n",
       "      <td> 1946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td>   To Catch a Thief</td>\n",
       "      <td> 1955</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               title  year\n",
       "director                                  \n",
       "Alfred Hitchcock  North by Northwest  1959\n",
       "Alfred Hitchcock           Notorious  1946\n",
       "Alfred Hitchcock    To Catch a Thief  1955"
      ]
     },
     "execution_count": 113,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y.loc['Alfred Hitchcock']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['North by Northwest', 'Notorious', 'To Catch a Thief'], dtype=object)"
      ]
     },
     "execution_count": 117,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y.at['Alfred Hitchcock','title']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'The Philadelphia Story'"
      ]
     },
     "execution_count": 118,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y.at['George Cukor','title']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'p' is not defined",
     "output_type": "error",
     "traceback": [
      "Traceback \u001b[1;36m(most recent call last)\u001b[0m:\n",
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-145-560ed8861e3e>\"\u001b[1;36m, line \u001b[1;32m1\u001b[1;36m, in \u001b[1;35m<module>\u001b[1;36m\u001b[0m\n\u001b[1;33m    p(df1.set_index('director'))\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m\u001b[1;31m:\u001b[0m name 'p' is not defined\n"
     ]
    }
   ],
   "source": [
    "p(df1.set_index('director'))"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "print(df1.set_index('director').set_index('title', append=True))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>title</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>North by Northwest</th>\n",
       "      <td> 1959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Notorious</th>\n",
       "      <td> 1946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>To Catch a Thief</th>\n",
       "      <td> 1955</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    year\n",
       "title                   \n",
       "North by Northwest  1959\n",
       "Notorious           1946\n",
       "To Catch a Thief    1955"
      ]
     },
     "execution_count": 125,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.set_index('director').set_index('title', append=True).loc['Alfred Hitchcock']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th>title</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Alfred Hitchcock</th>\n",
       "      <th>North by Northwest</th>\n",
       "      <td> 1959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Notorious</th>\n",
       "      <td> 1946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>George Cukor</th>\n",
       "      <th>The Philadelphia Story</th>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <th>To Catch a Thief</th>\n",
       "      <td> 1955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Howard Hawks</th>\n",
       "      <th>His Girl Friday</th>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         year\n",
       "director         title                       \n",
       "Alfred Hitchcock North by Northwest      1959\n",
       "                 Notorious               1946\n",
       "George Cukor     The Philadelphia Story  1940\n",
       "Alfred Hitchcock To Catch a Thief        1955\n",
       "Howard Hawks     His Girl Friday         1940"
      ]
     },
     "execution_count": 128,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.set_index(['director', 'title'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "'Key length (1) was greater than MultiIndex lexsort depth (0)'",
     "output_type": "error",
     "traceback": [
      "Traceback \u001b[1;36m(most recent call last)\u001b[0m:\n",
      "  File \u001b[0;32m\"<ipython-input-137-0f8b79e18ab8>\"\u001b[0m, line \u001b[0;32m1\u001b[0m, in \u001b[0;35m<module>\u001b[0m\n    df1.set_index(['director', 'title']).loc['Alfred Hitchcock':'George Cukor']\n",
      "  File \u001b[0;32m\"/home/brandon/.v/pandas-tutorial/lib/python3.4/site-packages/pandas/core/indexing.py\"\u001b[0m, line \u001b[0;32m1202\u001b[0m, in \u001b[0;35m__getitem__\u001b[0m\n    return self._getitem_axis(key, axis=0)\n",
      "  File \u001b[0;32m\"/home/brandon/.v/pandas-tutorial/lib/python3.4/site-packages/pandas/core/indexing.py\"\u001b[0m, line \u001b[0;32m1316\u001b[0m, in \u001b[0;35m_getitem_axis\u001b[0m\n    return self._get_slice_axis(key, axis=axis)\n",
      "  File \u001b[0;32m\"/home/brandon/.v/pandas-tutorial/lib/python3.4/site-packages/pandas/core/indexing.py\"\u001b[0m, line \u001b[0;32m1224\u001b[0m, in \u001b[0;35m_get_slice_axis\u001b[0m\n    slice_obj.step)\n",
      "  File \u001b[0;32m\"/home/brandon/.v/pandas-tutorial/lib/python3.4/site-packages/pandas/core/index.py\"\u001b[0m, line \u001b[0;32m2027\u001b[0m, in \u001b[0;35mslice_indexer\u001b[0m\n    start_slice, end_slice = self.slice_locs(start, end, step=step)\n",
      "  File \u001b[0;32m\"/home/brandon/.v/pandas-tutorial/lib/python3.4/site-packages/pandas/core/index.py\"\u001b[0m, line \u001b[0;32m4063\u001b[0m, in \u001b[0;35mslice_locs\u001b[0m\n    return super(MultiIndex, self).slice_locs(start, end, step)\n",
      "  File \u001b[0;32m\"/home/brandon/.v/pandas-tutorial/lib/python3.4/site-packages/pandas/core/index.py\"\u001b[0m, line \u001b[0;32m2141\u001b[0m, in \u001b[0;35mslice_locs\u001b[0m\n    start_slice = self.get_slice_bound(start, 'left')\n",
      "  File \u001b[0;32m\"/home/brandon/.v/pandas-tutorial/lib/python3.4/site-packages/pandas/core/index.py\"\u001b[0m, line \u001b[0;32m4035\u001b[0m, in \u001b[0;35mget_slice_bound\u001b[0m\n    return self._partial_tup_index(label, side=side)\n",
      "\u001b[1;36m  File \u001b[1;32m\"/home/brandon/.v/pandas-tutorial/lib/python3.4/site-packages/pandas/core/index.py\"\u001b[1;36m, line \u001b[1;32m4069\u001b[1;36m, in \u001b[1;35m_partial_tup_index\u001b[1;36m\u001b[0m\n\u001b[1;33m    (len(tup), self.lexsort_depth))\u001b[0m\n",
      "\u001b[1;31mKeyError\u001b[0m\u001b[1;31m:\u001b[0m 'Key length (1) was greater than MultiIndex lexsort depth (0)'\n"
     ]
    }
   ],
   "source": [
    "df1.set_index(['director', 'title']).loc['Alfred Hitchcock':'George Cukor']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th>title</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">Alfred Hitchcock</th>\n",
       "      <th>North by Northwest</th>\n",
       "      <td> 1959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Notorious</th>\n",
       "      <td> 1946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>To Catch a Thief</th>\n",
       "      <td> 1955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>George Cukor</th>\n",
       "      <th>The Philadelphia Story</th>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         year\n",
       "director         title                       \n",
       "Alfred Hitchcock North by Northwest      1959\n",
       "                 Notorious               1946\n",
       "                 To Catch a Thief        1955\n",
       "George Cukor     The Philadelphia Story  1940"
      ]
     },
     "execution_count": 138,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.set_index(['director', 'title']).sort_index().loc['Alfred Hitchcock':'George Cukor']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "df1.set_index(['director', 'title']).sort_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 154,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th>title</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">Alfred Hitchcock</th>\n",
       "      <th>North by Northwest</th>\n",
       "      <td> 1959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Notorious</th>\n",
       "      <td> 1946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>To Catch a Thief</th>\n",
       "      <td> 1955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>George Cukor</th>\n",
       "      <th>The Philadelphia Story</th>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Howard Hawks</th>\n",
       "      <th>His Girl Friday</th>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         year\n",
       "director         title                       \n",
       "Alfred Hitchcock North by Northwest      1959\n",
       "                 Notorious               1946\n",
       "                 To Catch a Thief        1955\n",
       "George Cukor     The Philadelphia Story  1940\n",
       "Howard Hawks     His Girl Friday         1940"
      ]
     },
     "execution_count": 154,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.groupby(['director', 'title']).first()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th>title</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">Alfred Hitchcock</th>\n",
       "      <th>North by Northwest</th>\n",
       "      <td> 1959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Notorious</th>\n",
       "      <td> 1946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>To Catch a Thief</th>\n",
       "      <td> 1955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>George Cukor</th>\n",
       "      <th>The Philadelphia Story</th>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Howard Hawks</th>\n",
       "      <th>His Girl Friday</th>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         year\n",
       "director         title                       \n",
       "Alfred Hitchcock North by Northwest      1959\n",
       "                 Notorious               1946\n",
       "                 To Catch a Thief        1955\n",
       "George Cukor     The Philadelphia Story  1940\n",
       "Howard Hawks     His Girl Friday         1940"
      ]
     },
     "execution_count": 134,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.groupby(['director', 'title']).first()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 184,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "#\n",
    "# Official diagram generation\n",
    "#\n",
    "\n",
    "open('u__tyd.html', 'w').write(df1.to_html())\n",
    "open('u_d_ty.html', 'w').write(df1.set_index('director').to_html())\n",
    "open('u_dt_y.html', 'w').write(df1.set_index('director').set_index('title', append=True).to_html())\n",
    "open('s_d_ty.html', 'w').write(df1.set_index('director').sort_index().to_html())\n",
    "open('s_dt_y.html', 'w').write(df1.set_index('director').set_index('title', append=True).sort_index().to_html())\n",
    "\n",
    "print(\n",
    "    df1.set_index('director').set_index('title', append=True).equals(\n",
    "    df1.set_index(['director', 'title'])\n",
    "    ))\n",
    "\n",
    "print(\n",
    "    df1.set_index(['director', 'title']).sort_index().equals(\n",
    "    df1.groupby(['director', 'title']).first()\n",
    "    ))\n",
    "\n",
    "print(\n",
    "    df1.set_index('director').sort_index().set_index('title', append=True).equals(\n",
    "    df1.groupby(['director', 'title']).first()\n",
    "    ))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 182,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>title</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>North by Northwest</th>\n",
       "      <td> 1959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Notorious</th>\n",
       "      <td> 1946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>To Catch a Thief</th>\n",
       "      <td> 1955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Philadelphia Story</th>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>His Girl Friday</th>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                        year\n",
       "title                       \n",
       "North by Northwest      1959\n",
       "Notorious               1946\n",
       "To Catch a Thief        1955\n",
       "The Philadelphia Story  1940\n",
       "His Girl Friday         1940"
      ]
     },
     "execution_count": 182,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.set_index('director').sort_index().set_index('title')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 179,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td>     North by Northwest</td>\n",
       "      <td> 1959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>George Cukor</th>\n",
       "      <td> The Philadelphia Story</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Howard Hawks</th>\n",
       "      <td>        His Girl Friday</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                   title  year\n",
       "director                                      \n",
       "Alfred Hitchcock      North by Northwest  1959\n",
       "George Cukor      The Philadelphia Story  1940\n",
       "Howard Hawks             His Girl Friday  1940"
      ]
     },
     "execution_count": 179,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>title</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>North by Northwest</th>\n",
       "      <td> 1959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Notorious</th>\n",
       "      <td> 1946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>To Catch a Thief</th>\n",
       "      <td> 1955</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    year\n",
       "title                   \n",
       "North by Northwest  1959\n",
       "Notorious           1946\n",
       "To Catch a Thief    1955"
      ]
     },
     "execution_count": 127,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.set_index(['director', 'title']).loc['Alfred Hitchcock']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td>     North by Northwest</td>\n",
       "      <td> 1959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td>              Notorious</td>\n",
       "      <td> 1946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>George Cukor</th>\n",
       "      <td> The Philadelphia Story</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td>       To Catch a Thief</td>\n",
       "      <td> 1955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Howard Hawks</th>\n",
       "      <td>        His Girl Friday</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                   title  year\n",
       "director                                      \n",
       "Alfred Hitchcock      North by Northwest  1959\n",
       "Alfred Hitchcock               Notorious  1946\n",
       "George Cukor      The Philadelphia Story  1940\n",
       "Alfred Hitchcock        To Catch a Thief  1955\n",
       "Howard Hawks             His Girl Friday  1940"
      ]
     },
     "execution_count": 129,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.set_index(['director', 'title']).reset_index('title')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>director</th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "      <td>     North by Northwest</td>\n",
       "      <td> 1959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "      <td>              Notorious</td>\n",
       "      <td> 1946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>     George Cukor</td>\n",
       "      <td> The Philadelphia Story</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "      <td>       To Catch a Thief</td>\n",
       "      <td> 1955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>     Howard Hawks</td>\n",
       "      <td>        His Girl Friday</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           director                   title  year\n",
       "0  Alfred Hitchcock      North by Northwest  1959\n",
       "1  Alfred Hitchcock               Notorious  1946\n",
       "2      George Cukor  The Philadelphia Story  1940\n",
       "3  Alfred Hitchcock        To Catch a Thief  1955\n",
       "4      Howard Hawks         His Girl Friday  1940"
      ]
     },
     "execution_count": 130,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.set_index(['director', 'title']).reset_index(['director', 'title'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "      <th>director</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>     North by Northwest</td>\n",
       "      <td> 1959</td>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>              Notorious</td>\n",
       "      <td> 1946</td>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td> The Philadelphia Story</td>\n",
       "      <td> 1940</td>\n",
       "      <td>     George Cukor</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>       To Catch a Thief</td>\n",
       "      <td> 1955</td>\n",
       "      <td> Alfred Hitchcock</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>        His Girl Friday</td>\n",
       "      <td> 1940</td>\n",
       "      <td>     Howard Hawks</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    title  year          director\n",
       "0      North by Northwest  1959  Alfred Hitchcock\n",
       "1               Notorious  1946  Alfred Hitchcock\n",
       "2  The Philadelphia Story  1940      George Cukor\n",
       "3        To Catch a Thief  1955  Alfred Hitchcock\n",
       "4         His Girl Friday  1940      Howard Hawks"
      ]
     },
     "execution_count": 131,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"3\" halign=\"left\">title</th>\n",
       "      <th colspan=\"3\" halign=\"left\">year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <th>George Cukor</th>\n",
       "      <th>Howard Hawks</th>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <th>George Cukor</th>\n",
       "      <th>Howard Hawks</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td> North by Northwest</td>\n",
       "      <td>                    NaN</td>\n",
       "      <td>             NaN</td>\n",
       "      <td> 1959</td>\n",
       "      <td>  NaN</td>\n",
       "      <td>  NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>          Notorious</td>\n",
       "      <td>                    NaN</td>\n",
       "      <td>             NaN</td>\n",
       "      <td> 1946</td>\n",
       "      <td>  NaN</td>\n",
       "      <td>  NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>                NaN</td>\n",
       "      <td> The Philadelphia Story</td>\n",
       "      <td>             NaN</td>\n",
       "      <td>  NaN</td>\n",
       "      <td> 1940</td>\n",
       "      <td>  NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>   To Catch a Thief</td>\n",
       "      <td>                    NaN</td>\n",
       "      <td>             NaN</td>\n",
       "      <td> 1955</td>\n",
       "      <td>  NaN</td>\n",
       "      <td>  NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>                NaN</td>\n",
       "      <td>                    NaN</td>\n",
       "      <td> His Girl Friday</td>\n",
       "      <td>  NaN</td>\n",
       "      <td>  NaN</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                       title                                           \\\n",
       "director    Alfred Hitchcock            George Cukor     Howard Hawks   \n",
       "0         North by Northwest                     NaN              NaN   \n",
       "1                  Notorious                     NaN              NaN   \n",
       "2                        NaN  The Philadelphia Story              NaN   \n",
       "3           To Catch a Thief                     NaN              NaN   \n",
       "4                        NaN                     NaN  His Girl Friday   \n",
       "\n",
       "                     year                            \n",
       "director Alfred Hitchcock George Cukor Howard Hawks  \n",
       "0                    1959          NaN          NaN  \n",
       "1                    1946          NaN          NaN  \n",
       "2                     NaN         1940          NaN  \n",
       "3                    1955          NaN          NaN  \n",
       "4                     NaN          NaN         1940  "
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.unstack(level=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th colspan=\"3\" halign=\"left\">Alfred Hitchcock</th>\n",
       "      <th>George Cukor</th>\n",
       "      <th>Howard Hawks</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>3</th>\n",
       "      <th>2</th>\n",
       "      <th>4</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>title</th>\n",
       "      <td> North by Northwest</td>\n",
       "      <td> Notorious</td>\n",
       "      <td> To Catch a Thief</td>\n",
       "      <td> The Philadelphia Story</td>\n",
       "      <td> His Girl Friday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>year</th>\n",
       "      <td>               1959</td>\n",
       "      <td>      1946</td>\n",
       "      <td>             1955</td>\n",
       "      <td>                   1940</td>\n",
       "      <td>            1940</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "director    Alfred Hitchcock                               \\\n",
       "                           0          1                 3   \n",
       "title     North by Northwest  Notorious  To Catch a Thief   \n",
       "year                    1959       1946              1955   \n",
       "\n",
       "director            George Cukor     Howard Hawks  \n",
       "                               2                4  \n",
       "title     The Philadelphia Story  His Girl Friday  \n",
       "year                        1940             1940  "
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.transpose()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td> North by Northwest</td>\n",
       "      <td> 1959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>          Notorious</td>\n",
       "      <td> 1946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>   To Catch a Thief</td>\n",
       "      <td> 1955</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                title  year\n",
       "0  North by Northwest  1959\n",
       "1           Notorious  1946\n",
       "3    To Catch a Thief  1955"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.ix['Alfred Hitchcock']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "title    To Catch a Thief\n",
       "year                 1955\n",
       "Name: (Alfred Hitchcock, 3), dtype: object"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.ix['Alfred Hitchcock',3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>first_year</th>\n",
       "      <th>last_year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td> 1946</td>\n",
       "      <td> 1959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>George Cukor</th>\n",
       "      <td> 1940</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Howard Hawks</th>\n",
       "      <td> 1940</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  first_year  last_year\n",
       "director                               \n",
       "Alfred Hitchcock        1946       1959\n",
       "George Cukor            1940       1940\n",
       "Howard Hawks            1940       1940"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.groupby('director')['year'].agg([('first_year', min), ('last_year', max)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td>     North by Northwest</td>\n",
       "      <td> 1959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>George Cukor</th>\n",
       "      <td> The Philadelphia Story</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Howard Hawks</th>\n",
       "      <td>        His Girl Friday</td>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                   title  year\n",
       "director                                      \n",
       "Alfred Hitchcock      North by Northwest  1959\n",
       "George Cukor      The Philadelphia Story  1940\n",
       "Howard Hawks             His Girl Friday  1940"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.groupby('director').agg({'title': min, 'year': max})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th>title</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">Alfred Hitchcock</th>\n",
       "      <th>North by Northwest</th>\n",
       "      <td> 1959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Notorious</th>\n",
       "      <td> 1946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>To Catch a Thief</th>\n",
       "      <td> 1955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>George Cukor</th>\n",
       "      <th>The Philadelphia Story</th>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Howard Hawks</th>\n",
       "      <th>His Girl Friday</th>\n",
       "      <td> 1940</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         year\n",
       "director         title                       \n",
       "Alfred Hitchcock North by Northwest      1959\n",
       "                 Notorious               1946\n",
       "                 To Catch a Thief        1955\n",
       "George Cukor     The Philadelphia Story  1940\n",
       "Howard Hawks     His Girl Friday         1940"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df3 = df1.groupby(['director', 'title']).first()\n",
    "df3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>title</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th>year</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">Alfred Hitchcock</th>\n",
       "      <th>1946</th>\n",
       "      <td>              Notorious</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1955</th>\n",
       "      <td>       To Catch a Thief</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1959</th>\n",
       "      <td>     North by Northwest</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>George Cukor</th>\n",
       "      <th>1940</th>\n",
       "      <td> The Philadelphia Story</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Howard Hawks</th>\n",
       "      <th>1940</th>\n",
       "      <td>        His Girl Friday</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                        title\n",
       "director         year                        \n",
       "Alfred Hitchcock 1946               Notorious\n",
       "                 1955        To Catch a Thief\n",
       "                 1959      North by Northwest\n",
       "George Cukor     1940  The Philadelphia Story\n",
       "Howard Hawks     1940         His Girl Friday"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df4 = df1.groupby(['director', 'year']).first()\n",
    "df4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th>title</th>\n",
       "      <th>year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: []\n",
       "Index: []"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.groupby(['director', 'title', 'year']).first()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0  title           North by Northwest\n",
       "   year                          1959\n",
       "   director          Alfred Hitchcock\n",
       "1  title                    Notorious\n",
       "   year                          1946\n",
       "   director          Alfred Hitchcock\n",
       "2  title       The Philadelphia Story\n",
       "   year                          1940\n",
       "   director              George Cukor\n",
       "3  title             To Catch a Thief\n",
       "   year                          1955\n",
       "   director          Alfred Hitchcock\n",
       "4  title              His Girl Friday\n",
       "   year                          1940\n",
       "   director              Howard Hawks\n",
       "dtype: object"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1 = df1.stack()\n",
    "s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "title     0        North by Northwest\n",
       "          1                 Notorious\n",
       "          2    The Philadelphia Story\n",
       "          3          To Catch a Thief\n",
       "          4           His Girl Friday\n",
       "year      0                      1959\n",
       "          1                      1946\n",
       "          2                      1940\n",
       "          3                      1955\n",
       "          4                      1940\n",
       "director  0          Alfred Hitchcock\n",
       "          1          Alfred Hitchcock\n",
       "          2              George Cukor\n",
       "          3          Alfred Hitchcock\n",
       "          4              Howard Hawks\n",
       "dtype: object"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2 = df1.unstack()\n",
    "s2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "director          title                       \n",
       "Alfred Hitchcock  North by Northwest      year    1959\n",
       "                  Notorious               year    1946\n",
       "                  To Catch a Thief        year    1955\n",
       "George Cukor      The Philadelphia Story  year    1940\n",
       "Howard Hawks      His Girl Friday         year    1940\n",
       "dtype: int64"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df3.stack()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"5\" halign=\"left\">year</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>title</th>\n",
       "      <th>His Girl Friday</th>\n",
       "      <th>North by Northwest</th>\n",
       "      <th>Notorious</th>\n",
       "      <th>The Philadelphia Story</th>\n",
       "      <th>To Catch a Thief</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>director</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alfred Hitchcock</th>\n",
       "      <td>  NaN</td>\n",
       "      <td> 1959</td>\n",
       "      <td> 1946</td>\n",
       "      <td>  NaN</td>\n",
       "      <td> 1955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>George Cukor</th>\n",
       "      <td>  NaN</td>\n",
       "      <td>  NaN</td>\n",
       "      <td>  NaN</td>\n",
       "      <td> 1940</td>\n",
       "      <td>  NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Howard Hawks</th>\n",
       "      <td> 1940</td>\n",
       "      <td>  NaN</td>\n",
       "      <td>  NaN</td>\n",
       "      <td>  NaN</td>\n",
       "      <td>  NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                            year                               \\\n",
       "title            His Girl Friday North by Northwest Notorious   \n",
       "director                                                        \n",
       "Alfred Hitchcock             NaN               1959      1946   \n",
       "George Cukor                 NaN                NaN       NaN   \n",
       "Howard Hawks                1940                NaN       NaN   \n",
       "\n",
       "                                                          \n",
       "title            The Philadelphia Story To Catch a Thief  \n",
       "director                                                  \n",
       "Alfred Hitchcock                    NaN             1955  \n",
       "George Cukor                       1940              NaN  \n",
       "Howard Hawks                        NaN              NaN  "
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df3.unstack()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.4.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
